<!doctype html>
<html  class="login">
<head>
<meta charset="utf-8">
<title>登录</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="${s.base}/phone/css/common.css">
<link rel="stylesheet" href="${s.base}/phone/css/font-awesome.css">
</head>
<body  class="login">
<input type="hidden" id="openid" class="login-input" value="${openid}"/>
<input type="hidden" id="personType" class="login-input" value="1"/>

	<div class="login-logo"><img src="${s.base}/phone/images/logo.png"/></div>
	<h1 class="login-title">学生登录</h1>
	<div class="login-cotent">
		<form>
			<div class="form-group">
				<input type="text" id="name" class="login-input" placeholder="学号"/><i class="fa fa-user-o fa-lg" id="tubiao"></i>
			</div>
			<div class="form-group" style="display: none;">
				<input type="text" id="phone" class="login-input" placeholder="手机号"/><i class="fa fa-unlock-alt fa-lg" id="tubiao"></i>
			</div>
			<div class="form-group" >
				<input type="password" id="password" class="login-input" placeholder="密码"/><i class="fa fa-unlock-alt fa-lg" id="tubiao"></i>
			</div>
			<div class="form-group">
				<input type="button" id="submitBtn" class="login-button" value="登录" />
			</div>
			<div class="user">家长登录</div><div class="user2">教师登录</div>
		</form>
	</div>

<script src="${s.base}/js/jquery-3.2.0.min.js"></script>
<script  type="application/javascript" src="${s.base}/js/layer/layer.js" ></script>
<script  type="application/javascript" src="${s.base}/js/layer/commont.js" ></script>
<script type="text/javascript">
	$(document).ready(function () {
		$(".user,.user2").bind("click",function () {
			change($(this).html());
        })
        $("#submitBtn").click(function () {
            var openid=$("#openid").val();
            var personType=$("#personType").val();
            var name=$("#name").val();
            var password=$("#password").val();
            var phone=$("#phone").val();
            if(name == "" || name==null){
                offset("auto","请输入"+$("#name").attr("placeholder")+"！","登录提示","确定");
                return false;
            }
            if(personType=="3"){
                if(phone == "" || phone==null){
                    offset("auto","请输入"+$("#phone").attr("placeholder")+"！","登录提示","确定");
                    return false;
                }
			}else{
                if(password == "" || password==null){
                    offset("auto","请输入"+$("#password").attr("placeholder")+"！","登录提示","确定");
                    return false;
                }
			}


            var url="${s.base}/mobile/login";
            var params = {
                openid: openid,
                personType: personType,
                phone: phone,
                name: name,
                password: password
            };
            //调用了jquery.json 库
			/* var encoded = $.toJSON( request );
			 var jsonStr = encoded;*/
            $.ajax({
                url : url,
                type : 'POST',
                data : params,
                dataType : 'json',
                //contentType : 'application/json',
                success : function(data, status, xhr) {
                    if(1==data.returnInfo.state){
                        //offset("auto","登录成功","登录提示","确定");
                        location.href="/"+data.returnInfo.result;
                    }else{
                        offset("auto",data.returnInfo.errorMsg,"登录提示","确定");
                    }

                },
                Error : function(xhr, error, exception) {
                    // handle the error.
                    offset("auto",exception.toString(),"登录提示","确定");
                }
            });
        })
    })

	function change(obj) {
		if(obj=="学生登录"){
		    //学生登录页面
			$(".login-title").html("学生登录");
            $(".user").html("家长登录");
            $(".user2").html("教师登录");
            $("#name").attr("placeholder","学号");
            $("#phone").parent().hide();
            $("#password").parent().show();
            $("#personType").val("1");
		}else if(obj=="教师登录"){
            //教师登录页面
            $(".login-title").html("教师登录");
            $(".user").html("学生登录");
            $(".user2").html("家长登录");
            $("#name").attr("placeholder","工号");
            $("#phone").parent().hide();
            $("#password").parent().show();
            $("#personType").val("2");
        }else if(obj=="家长登录"){
            //家长登录页面
            $(".login-title").html("家长登录");
            $(".user").html("学生登录");
            $(".user2").html("教师登录");
            $("#name").attr("placeholder","姓名");
            $("#phone").parent().show();
            $("#password").parent().hide();
            $("#personType").val("3");
        }
    }


</script>
	</body>
</html>
